package org.gd136.ce.script.impl;

import org.gd136.ce.script.Script;
import org.gd136.ce.script.ScriptStage;

public class DialogScript extends Script {

	public static boolean isDialogShowd = false;
	boolean isHasArgument = false;
	boolean isActionShow = false;

	private static final String TAG = "#dialog ";

	@Override
	public Script readScript(String scriptLine) {
		DialogScript ds = null;
		if (scriptLine.startsWith(TAG)) {
			ds = new DialogScript();
			String param = scriptLine.substring(TAG.length()).trim();
			if ("show".equals(param)) {
				ds.isHasArgument = true;
				ds.isActionShow = true;
			} else if ("hide".equals(param)) {
				ds.isHasArgument = true;
				ds.isActionShow = false;
			}

			ds.addToPoolAndLinkFrontScript();
		}
		return ds;
	}

	@Override
	public void execute(ScriptStage stage) {
		if (isHasArgument) {
			if (isActionShow != isDialogShowd) {
				isDialogShowd = isActionShow;
				stage.dialogVisible(isActionShow);
			}
		} else {
			isDialogShowd = !isDialogShowd;
			stage.dialogVisible(isDialogShowd);
		}
	}

}
